/*
 * File    : /part1/connect.js
 * Time    : 2021-03-21 18:56:50
 * Author  : Gray Snail
 * Version : 1.0
 * Contact : shtao2011@sina.com
 * License : Copyright (c) 2021 Gray Snail
 * Desc    : None
 */

const { Sequelize } = require('sequelize')

// URI or option
// const sequelize = new Sequelize('billing', 'root', '943712', {
//     host: 'localhost',
//     dialect: 'mysql',
// })

// const sequelize = new Sequelize({
//     dialect: 'sqlite',
//     storage: 'path/to/database.sqlite',
// })

// sqlite 内存数据库
const sequelize = new Sequelize('sqlite::memory:', {
    logging: (...msg) => console.log(msg),
})

async function connect() {
    try {
        await sequelize.authenticate()
        console.log('Connection Successful')

        const res = await sequelize.close()
        console.log('Close', res)
    } catch (error) {
        console.error('Unable to connect to database', error)
    }
}

connect()
